package com.zjw.controller;

import com.zjw.annotation.SystemLog;
import com.zjw.annotation.domain.ResponseResult;
import com.zjw.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

//    @PostMapping("/test")
//    public List<Article> test() {
//        return articleService.getArticleList();
//    }

    /**
     * 获取热门文章列表
     *
     * @return {@link ResponseResult}
     */
    @SystemLog("热门文章列表")
    @RequestMapping(value = "/hotArticleList", method = RequestMethod.GET)
    public ResponseResult getHotArticleList() {
        return articleService.getHotArticleList();
    }


    /**
     * 文章列表
     *
     * @param pageNum    页码
     * @param pageSize   页面大小
     * @param categoryId 类别 ID
     * @return {@link ResponseResult}
     */
    @SystemLog("文章列表")
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum, Integer pageSize, Long categoryId) {

        System.out.println(pageNum.toString() + pageSize.toString() + categoryId.toString());
        ResponseResult res =  articleService.articleList(pageNum, pageSize, categoryId);
        return res;
    }


    /**
     * 按 ID 获取文章
     *
     * @return {@link ResponseResult}
     */
    @GetMapping("/{id}")
    @SystemLog("获取指定id文章")
    public ResponseResult getArticleById(@PathVariable Long id){
        return articleService.getArticleById(id);
    }


    @PutMapping("/updateViewCount/{id}")
    @SystemLog("文章浏览量更新")
    public ResponseResult updateViewCount(@PathVariable Long id){
        return articleService.updateViewCount(id);
    }

}
